//
//  ZHMineSetViewController.m
//  LoveFreshBee
//
//  Created by brice Mac on 2016/10/17.
//  Copyright © 2016年 王忠迪. All rights reserved.
//

#import "ZHMineSetViewController.h"
#import "SVProgressHUD.h"
#import "LFNetworkTools.h"

#define subViewHeight 50
#define navHeight 64

@interface ZHMineSetViewController ()

@property(nonatomic,weak)UIView *aboutMeView;

@property(nonatomic,weak)UIView *cleanCacheView;

@property(nonatomic,weak)UILabel *cacheNumberLabel;

@property(nonatomic,weak)UIView *logoutView;

@end

@implementation ZHMineSetViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupMineSettingUI];
}

// 视图不用tableView, 用View
- (void)setupTableView {
    
}

- (void)setupMineSettingUI {
    
    self.navItem.title = @"设置";
    
    [self setupAboutMeView];
    
    [self setupCleanCacheView];
    
    [self setupLogoutView];
}

- (void)setupAboutMeView {
    
    UIView *aboutMeView = [[UIView alloc]initWithFrame:CGRectMake(0, navHeight + 11, kScreenW, 50)];
    _aboutMeView = aboutMeView;
    _aboutMeView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:aboutMeView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(aboutMeViewClick)];
    
    [aboutMeView addGestureRecognizer:tap];
    
    UILabel *aboutLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 200, 50)];
    aboutLabel.text = @"关于小熊";
    aboutLabel.font = [UIFont systemFontOfSize:16];
    [aboutMeView addSubview:aboutLabel];
    
    //右边箭头
    UIImageView *arrowView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_go"]];
    arrowView.frame = CGRectMake(kScreenW - 30, 20, 5, 10);
    [aboutMeView addSubview:arrowView];
    
}

- (void)setupCleanCacheView {
    UIView *cleanCacheView = [[UIView alloc] initWithFrame:CGRectMake(0,  subViewHeight + navHeight + 11, kScreenW, subViewHeight)];
    cleanCacheView.backgroundColor = [UIColor whiteColor];
    _cleanCacheView = cleanCacheView;
    [self.view addSubview:cleanCacheView];
    
    UILabel *cleanCacheLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 200, subViewHeight)];
    cleanCacheLabel.text = @"清理缓存";
    cleanCacheLabel.font = [UIFont systemFontOfSize:16];
    [cleanCacheView addSubview:cleanCacheLabel];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cleanCacheViewClick)];
    [cleanCacheView addGestureRecognizer:tap];
    UILabel *cacheNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(150, 0, kScreenW - 165, subViewHeight)];
    _cacheNumberLabel = cacheNumberLabel;
    cacheNumberLabel.textAlignment = NSTextAlignmentRight;
    cacheNumberLabel.textColor = [UIColor lightGrayColor];
    cacheNumberLabel.text = [@"60.1" stringByAppendingString:@"M"];
//    cacheNumberLabel.text = String().stringByAppendingFormat("%.2fM", FileTool.folderSize(LFBCachePath)).cleanDecimalPointZear()
    [cleanCacheView addSubview:cacheNumberLabel];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(5, -0.5, kScreenW - 10, 0.5)];
    line.backgroundColor = [UIColor blackColor];
    line.alpha = 0.2;
    [cleanCacheView addSubview:line];
}

- (void)setupLogoutView {
    UIView *logOutView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_cleanCacheView.frame) + 20, kScreenH, subViewHeight)];
    logOutView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:logOutView];
    
    UILabel *logOutLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW, subViewHeight)];
    logOutLabel.text = @"退出当前账号";
    logOutLabel.textColor = [UIColor darkGrayColor];
    logOutLabel.textAlignment = NSTextAlignmentCenter;
    logOutLabel.font = [UIFont systemFontOfSize:16];
    [logOutView addSubview:logOutLabel];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(logOutViewClick)];
    [logOutView addGestureRecognizer:tap];
}

- (void)aboutMeViewClick {
    
    //跳转个人页面
    
}

- (void)cleanCacheViewClick {
    
    [SVProgressHUD showInfoWithStatus:@"正在清理"];
    // 延迟1s 清理完成
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [SVProgressHUD showSuccessWithStatus:@"清理成功"];
        [SVProgressHUD dismissWithDelay:1];
        self.cacheNumberLabel.text = @"0.00M";
    });
}

- (void)logOutViewClick {
    
    [SVProgressHUD showInfoWithStatus:@"已退出, 请重新登陆！"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismissWithDelay:2];
    });
}

@end



